import torch
tensor =torch.tensor([[1,2,3],[4,5,6]],dtype=torch.float32)
print('tensor:\n',tensor) #查看张量本身
print('shape of tensor:\n',tensor.shape)#查看张量形状
print('size of tensor:\n',tensor.size())#查看张量维度与上同
print("data type of tensor:\n",tensor.dtype)#查看数据类型
print('device of tensor:\n',tensor.device)#查看设备
print('dimensions of tensor:\n',tensor.dim())#查看维度数
print('total elements:\n',tensor.numel())#查看元素
print('requires grad:\n',tensor.requires_grad)#是否启用梯度
print('Is cuda :\n',tensor.is_cuda)#是否在gpu上
print('is contiguous:\n',tensor.is_contiguous)#是否连续存储
#获取单元素值
single_value=torch.tensor(42)
print('Single Element Value:',single_value.item())
#转置张量
tensor_T=tensor.T
print('Transposed Tensor:\n',tensor_T)
double_value=torch.tensor([42])
print('double tensor:',double_value)

